#!/usr/bin/python3
import os
import subprocess

def compile_c_files(directory):
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.lower().endswith('.c') and ('app' in file.lower() or 'App' in file.lower()):
                input_file = os.path.join(root, file)
                output_file = os.path.join(root, file[:-2] + '.out')  # 去掉.c，添加.out
                try:
                    # 使用subprocess调用编译器
                    compile_command = ['arm-none-linux-gnueabihf-gcc', '-o', output_file, input_file]
                    subprocess.run(compile_command, check=True)
                    print(f"Compiled: {input_file} to {output_file}")
                except subprocess.CalledProcessError as e:
                    print(f"Error compiling {input_file}: {e}")

if __name__ == "__main__":
    current_directory = '.'  # 当前目录
    compile_c_files(current_directory)
